package main

import (
	"google.golang.org/grpc"
	"gowork/serverStream/message"
	"io"
	"fmt"
	"context"
	"time"
)

var OrderMap = map[string]*message.OrderRequest{
	"201907300001": &message.OrderRequest{OrderId: "201907300001", TimeStamp:time.Now().Unix()},
	"201907310001": &message.OrderRequest{OrderId: "201907310001", TimeStamp:time.Now().Unix()},
	"201907310002": &message.OrderRequest{OrderId: "201907310002", TimeStamp:time.Now().Unix()},
	"201907310003": &message.OrderRequest{OrderId: "201907310003", TimeStamp:time.Now().Unix()},
	"201907310004": &message.OrderRequest{OrderId: "201907310004", TimeStamp:time.Now().Unix()},
	"201907310005": &message.OrderRequest{OrderId: "201907310005", TimeStamp:time.Now().Unix()},
	"201907310006": &message.OrderRequest{OrderId: "201907310006", TimeStamp:time.Now().Unix()},
	"201907310007": &message.OrderRequest{OrderId: "201907310007", TimeStamp:time.Now().Unix()},
	"201907310008": &message.OrderRequest{OrderId: "201907310008", TimeStamp:time.Now().Unix()},
	"201907310009": &message.OrderRequest{OrderId: "201907310009", TimeStamp:time.Now().Unix()},
	"201907310010": &message.OrderRequest{OrderId: "201907310010", TimeStamp:time.Now().Unix()},
	"201907310011": &message.OrderRequest{OrderId: "201907310011", TimeStamp:time.Now().Unix()},
	"201907310012": &message.OrderRequest{OrderId: "201907310012", TimeStamp:time.Now().Unix()},
	"201907310013": &message.OrderRequest{OrderId: "201907310013", TimeStamp:time.Now().Unix()},
	"201907310014": &message.OrderRequest{OrderId: "201907310014", TimeStamp:time.Now().Unix()},
	"201907310015": &message.OrderRequest{OrderId: "201907310015", TimeStamp:time.Now().Unix()},
	"201907310016": &message.OrderRequest{OrderId: "201907310016", TimeStamp:time.Now().Unix()},
	"201907310017": &message.OrderRequest{OrderId: "201907310017", TimeStamp:time.Now().Unix()},
	"201907310018": &message.OrderRequest{OrderId: "201907310018", TimeStamp:time.Now().Unix()},
	"201907310019": &message.OrderRequest{OrderId: "201907310019", TimeStamp:time.Now().Unix()},
	"201907310020": &message.OrderRequest{OrderId: "201907310020", TimeStamp:time.Now().Unix()},
	"201907310021": &message.OrderRequest{OrderId: "201907310021", TimeStamp:time.Now().Unix()},
	"201907310022": &message.OrderRequest{OrderId: "201907310022", TimeStamp:time.Now().Unix()},
	"201907310023": &message.OrderRequest{OrderId: "201907310023", TimeStamp:time.Now().Unix()},
	"201907310024": &message.OrderRequest{OrderId: "201907310024", TimeStamp:time.Now().Unix()},
	"201907310025": &message.OrderRequest{OrderId: "201907310025", TimeStamp:time.Now().Unix()},
	"201907310026": &message.OrderRequest{OrderId: "201907310026", TimeStamp:time.Now().Unix()},
	"201907310027": &message.OrderRequest{OrderId: "201907310027", TimeStamp:time.Now().Unix()},
	"201907310028": &message.OrderRequest{OrderId: "201907310028", TimeStamp:time.Now().Unix()},
	"201907310029": &message.OrderRequest{OrderId: "201907310029", TimeStamp:time.Now().Unix()},
	"201907310030": &message.OrderRequest{OrderId: "201907310030", TimeStamp:time.Now().Unix()},
	"201907310031": &message.OrderRequest{OrderId: "201907310031", TimeStamp:time.Now().Unix()},
	"201907310032": &message.OrderRequest{OrderId: "201907310032", TimeStamp:time.Now().Unix()},
	"201907310033": &message.OrderRequest{OrderId: "201907310033", TimeStamp:time.Now().Unix()},
}

func main() {
	//1、Dail连接
	conn, err := grpc.Dial("localhost:8090", grpc.WithInsecure())
	if err != nil {
		panic(err.Error())
	}
	defer conn.Close()

	orderServiceClient := message.NewOrderServiceClient(conn)
	var orders message.OrderList
	for _, v := range OrderMap{
		orders.OrderList = append(orders.OrderList, v)
	}
	orderInfosClient, err := orderServiceClient.GetOrderInfos(context.TODO(), &orders)

	go func() {
		for {
			orderInfo, err := orderInfosClient.Recv()
			if err == io.EOF {
				fmt.Println("读取结束")
				return
			}
			if err != nil {
				panic(err.Error())
			}
			fmt.Println("读取到的信息：", len(orderInfo.OrderInfoList))
		}
	}()

	select {}
}
